package com.gitee.feizns.dynamic;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

/**
 * 同步引用值
 * @author feizns
 * @since 2023/06/02
 */
@NoArgsConstructor
@AllArgsConstructor
public class Ref<T> {

    /**
     * 值
     */
    private T value;

    /**
     * 设置值
     * @param value {@link T}
     */
    public T set(T value) {
        T old = this.value;
       this.value = value;
       return old;
   }

    /**
     * 获取值
     * @return {@link T}
     */
    public T get() {
       return value;
   }

    /**
     * 为空
     * @return boolean
     */
    public boolean isNull() {
       return value == null;
   }

    /**
     * 值
     * @param value 价值
     * @return {@link Ref}<{@link T}>
     */
    public static <T> Ref<T> of(T value) {
        return new Ref<>(value);
    }

}
